package com.cet.lxf.collection.test11;

import java.util.Deque;
import java.util.LinkedList;

/**
 * @program: algorithm
 * @description: 十进制转化为十六进制
 * @author: 陈恩涛
 * @create: 2021-08-16 22:14
 **/
public class Main {
    public static void main(String[] args) {
        String hex = toHex(12500);
        if (hex.equalsIgnoreCase("30D4")) {
            System.out.println("测试通过");
        } else {
            System.out.println("测试失败");
        }
    }

    static String toHex(int n) {
        Deque<Character> deque = new LinkedList<>();
        while (n != 0) {
            int remainder = n % 16;
            if (remainder < 10) {
                deque.push((char) ('0'+remainder));
            } else {
                deque.push((char)('A' + (remainder - 10)));
            }
            n = n / 16;
        }
        StringBuilder result = new StringBuilder();
        while (deque.peek() != null) {
            result.append(deque.pop());
        }
        return result.toString();
    }
}

